package com.example.seckill.applicatoin.exception;

import org.springframework.http.HttpStatus;

public enum ResultCodeMapper {
    /**
     * 成功
     */
    SUCCESS(1, HttpStatus.OK),
    /**
     * 未识别错误
     */
    UNEXPECTED_ERROR(2, HttpStatus.INTERNAL_SERVER_ERROR),
    /**
     * 未识别错误
     */
    STOCK_ERROR(3, HttpStatus.NOT_FOUND);

    ResultCodeMapper(int errorCode, HttpStatus status) {
        this.code = errorCode;
        this.status = status;
    }
    public static ResultCodeMapper getInstanceByCode(int code) {
        for (ResultCodeMapper instance : ResultCodeMapper.values()) {
            if (instance.getCode() == code) {
                return instance;
            }
        }
        return null;
    }

    private int code;

    private HttpStatus status;

    public int getCode() {
        return code;
    }


    public HttpStatus getStatus() {
        return status;
    }
}
